package com.hq.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hq.bean.MingXi;
import com.hq.bean.PinPai;
import com.hq.bean.User;
import com.hq.service.PinPaiService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class PinPaiController {
    @Resource
    private PinPaiService pinPaiService;
    @RequestMapping("list.do")
    public String list(@RequestParam(value = "cpage",defaultValue = "1")Integer cpage,
                       String datatimeD,
                       String datatimeX,
                       Integer zhubanbenhaoD,
                       Integer zhubanbenhaoX,
                       Integer congbanbenhaoD,
                       Integer congbanbenhaoX,
                       String huituwenjian,
                       String zhizuorem,
                       String shengheren, Model model
                       ){
        HashMap map = new HashMap();
        map.put("datatimeD",datatimeD);
        map.put("datatimeX",datatimeX);
        map.put("zhubanbenhaoD",zhubanbenhaoD);
        map.put("zhubanbenhaoX",zhubanbenhaoX);
        map.put("congbanbenhaoD",congbanbenhaoD);
        map.put("congbanbenhaoX",congbanbenhaoX);
        map.put("huituwenjian",huituwenjian);
        map.put("zhizuorem",zhizuorem);
        map.put("shengheren",shengheren);
        PageHelper.startPage(cpage,3);
        List list = pinPaiService.list(map);
        PageInfo pageInfo = new PageInfo(list);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("map",map);
        return "list";
    }
    @RequestMapping("login.do")
    public String login(User user, HttpSession session){
        User login = pinPaiService.login(user);
        if (login!=null){
            session.setAttribute("user",user);
            return "redirect:list.do";
        }else {
            return "redirect:index.jsp";
        }
    }
    @RequestMapping("toadd.do")
    public String toadd(Model model){
        HashMap map = new HashMap();
        List list1 = pinPaiService.list1(map);
        model.addAttribute("list1",list1);
        return "add";
    }
    @RequestMapping("add.do")
    @ResponseBody
    public Object add(PinPai pinPai){
        int add = pinPaiService.add(pinPai);
        return add;
    }

    @RequestMapping("addmi.do")
    public String addmi(){
        return "addd";
    }
    @RequestMapping("addd.do")
    @ResponseBody
    public Object addd(MingXi mingXi){
        int addd = pinPaiService.addd(mingXi);
        return addd;
    }
    @RequestMapping("del.do")
    @ResponseBody
    public Object del(Integer mid){
        int del = pinPaiService.del(mid);
        return del;
    }
    @RequestMapping("list2.do")
    public String list2(Map map){
        List list = pinPaiService.list2(map);
        return "list";
    }
    @RequestMapping("list3.do")
    public String list3(Map map){
        List list = pinPaiService.list3(map);
        return "list";

    }
    @RequestMapping("list4.do")
    public String list4(Map map){
        List list = pinPaiService.list4(map);
        return "list";
    }
}
